package main
import "fmt"

func main(){
	//切片的循环遍历
	var strSlice=[]string{"java","cpp","golang"}
	for i:=0;i<len(strSlice);i++{
		fmt.Printf("%s\n",strSlice[i])
	}

	for k,v:=range strSlice{
		fmt.Println(k,v)
	}

	for _,v:=range strSlice{
		fmt.Println(v)
	}


	//基于数组定义切片
	arr1:=[...]int{35,36,37,378,40}
	arr2:=arr1[:]

	fmt.Printf("%v-type:%T\n",arr2,arr2)
	fmt.Printf("%v-type:%T\n",arr1,arr1)

	arr3:=arr1[1:4]//{36,37,378}
	fmt.Println(arr3)
	arr4:=arr1[:3]//{35,36,37}
	arr5:=arr1[3:]//{378,40}
	fmt.Println(arr4)
	fmt.Println(arr5)

	//基于切片的切片

	strarr:=[]string{"北京","上海","深圳","广州","杭州","苏州","重庆","成都"}
	strtmp:=strarr[:]
	strtmp1:=strarr[2:6]

	for k,v:=range strtmp{
		fmt.Println(k,v)
	}
	for i:=0;i<len(strtmp1);i++{
		fmt.Println(strtmp1[i])
	}

	//切片的长度和容量
	//切片的长度就是切片中元素的个数
	//切片的容量就是从第一数开始数  到达底层数组最后一个数的个数
	strarr1:=strarr[:4]
	strarr2:=strarr[1:4]
	fmt.Printf("len=%d,cap=%d\n",len(strarr),cap(strarr))//8 8
	fmt.Printf("len=%d,cap=%d\n",len(strarr1),cap(strarr1))//4 8
	fmt.Printf("len=%d,cap=%d\n",len(strarr2),cap(strarr2))//3 7
	strarr3:=strarr[4:]
	fmt.Printf("len=%d,cap%d\n",len(strarr3),cap(strarr3))//4 4


}